package com.newsnetwork.api.controller.files;


import com.newsnetwork.grace.result.CommonJSONResult;
import com.newsnetwork.pojo.bo.NewAdminBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author DingNing
 * @date 2022/11/7 10:41
 * @Description:
 */
@Api(value = "文件上传的Controller", tags = {"文件上传的Controller"})
@RequestMapping("fs")
public interface FileUploaderControllerApi {


    /**
     * 上传单文件
     * @param userId 用户ID
     * @param file 文件对象
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "上传用户头像", notes = "上传用户头像", httpMethod = "POST")
    @PostMapping("/uploadFace")
    CommonJSONResult uploadFace(@RequestParam String userId,
                                MultipartFile file) throws Exception;

    /**
     * 多文件上传
     * @param userId
     * @param files
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "多文件上传", notes = "多文件上传", httpMethod = "POST")
    @PostMapping("/uploadSomeFiles")
    CommonJSONResult uploadSomeFiles(@RequestParam String userId,
                                MultipartFile[] files) throws Exception;


    /**
     * 文件上传到 mongodb 的 gridFS 中, 无法使用 swagger 调用
     * @param newAdminBO adminBO 对象体
     */
    @PostMapping("/uploadToGridFS")
    CommonJSONResult uploadToGridFS(@RequestBody NewAdminBO newAdminBO) throws Exception;

    /**
     * 从 gridFS 中读取图片内容
     * @param faceId 图片id
     */
    @GetMapping("/readInGridFS")
    void readInGridFS(@RequestParam String faceId,
                                  HttpServletRequest request,
                                  HttpServletResponse response) throws Exception;
}
